let id=0
export default class Dep{
    constructor(){
        this.id=id++
        this.sub=[]    //watch收集容器
    }
    addSub(watcher){
       this.sub.push(watcher)
    }
    depend(){
        //显然watcher收集dep，收集完，在让dep收集watcher，多对多的对应关系
        Dep.target.addDep(this)
    }
    notify(){
       this.sub.forEach(watch=>{
           watch.update()
       })
    }
}

let stack=[]
export function pushTarget(watcher){
   Dep.target=watcher
   stack.push(watcher)
}

export function popTarget(watcher){
    stack.pop()
    Dep.target=stack[stack.length-1]
}